﻿using System.ComponentModel;

namespace OperationPlugins.Models
{
    public class ModelPropertyChangingEventArgs : PropertyChangingEventArgs
    {
        private readonly object _model;
        private readonly PropertyValue _newValue;
        private readonly PropertyValue _oldValue;

        /// <summary>
        /// Initializes a new instance of the ModelPropertyChangingEventArgs class.
        /// </summary>
        /// <param name="model">The model that contains the property that is changing.</param>
        /// <param name="newValue">The new value of the property that is changing.</param>
        /// <param name="oldValue">The old value of the property that is changing.</param>
        public ModelPropertyChangingEventArgs(object model, PropertyValue newValue, PropertyValue oldValue)
            : base(newValue.PropertyName)
        {
            _model = model;
            _newValue = newValue;
            _oldValue = oldValue;
        }

        /// <summary>
        /// Gets the model that contains the property that is changing.
        /// </summary>
        public object Model { get { return _model; } }

        /// <summary>
        /// Gets the new value of the property that is changing.
        /// </summary>
        public PropertyValue NewValue { get { return _newValue; } }

        /// <summary>
        /// Gets the old value of the property that is changing.
        /// </summary>
        public PropertyValue OldValue { get { return _oldValue; } }

        /// <summary>
        /// True if the property changing should be cancelled, otherwise false. 
        /// The default value is false.
        /// </summary>
        public bool Cancel { get; set; }
    }
}
